package routers

import (
	"io/ioutil"

	"github.com/gin-gonic/gin"
	cors "github.com/itsjamie/gin-cors"
)

func Run() *gin.Engine {
	gin.SetMode(gin.ReleaseMode)
	gin.DefaultWriter = ioutil.Discard
	engine := gin.Default()
	engine.Use(cors.Middleware(cors.Config{
		Origins:         "*",
		Methods:         "GET, PUT, POST, DELETE",
		RequestHeaders:  "Content-Type,Authorization,RoleId,Uid,x-requested-with",
		ExposedHeaders:  "Content-Type,Authorization,RoleId,Uid,x-requested-with",
		Credentials:     true,
		ValidateHeaders: false,
	}))

	engine.GET("health", func(context *gin.Context) {
		//new(common.Redis).Get().Del(new(common.Redis).GetBaseBatchCreateFashionLastNumKey())
		context.JSON(200, map[string]string{"msg": "ok"})
		return
	})

	RegisteAuth(engine)
	RegisteBase(engine)
	RegisteUser(engine)
	RegisteOrder(engine)

	return engine
}
